from django.db import models

# Create your models here.

# 用户信息模型
class User(models.Model):
	username = models.CharField(max_length=30)
	phone = models.CharField(max_length=11)
	password = models.CharField(max_length=78)
	email = models.CharField(max_length=30,null=True)
	age = models.IntegerField(null=True)
	sex = models.IntegerField(default=1)
	# 账号的状态：status（ # 0 正常  1禁用  2管理员  3删除）
	# 管理员可以登录后台
	status = models.IntegerField(default=0)
	addtime = models.DateTimeField(auto_now_add=True)


## 商品分类模型

class Type(models.Model):
	# 分类的名称
	name = models.CharField(max_length=20)
	# 父级id
	pid = models.IntegerField()
	# 路径（0,1，...）之类的，一级级向上找出父级的id
	path = models.CharField(max_length=30)







# 订单模型
# 一个收货地址可以对应着多个订单表
# 一个用户可以对应多个地址
# 地址模型：id,收货人，收货地址，收货电话，普通地址还是默认地址
# 一个订单可以对应着对个订单详情表(即多个商品信息)

class Address(models.Model):
	# 用户id
	uid = models.ForeignKey(to="User", to_field="id",on_delete=models.CASCADE)
	addressname = models.CharField(max_length=10)
	address = models.CharField(max_length=100)
	addressphone = models.CharField(max_length=11)
	# 1 为默认地址；0 为普通地址
	status = models.IntegerField(default=0)

# 订单表
# 用户id,地址，总价，总数，状态，添加时间
class Order(models.Model):
	uid = models.ForeignKey(to="User", to_field="id",on_delete=models.CASCADE)
	address = models.ForeignKey(to="Address",to_field="id",on_delete=models.CASCADE)
	totalprice = models.IntegerField()
	totalnum = models.IntegerField()
	# 1 未付款  2已付款,待发货  3已发货,待收货  4已完成  5已取消
	status = models.IntegerField()
	addtime = models.DateTimeField(auto_now_add=True)

# 订单编号，商品编号，数量，价格
class OrderInfo(models.Model):
	orderid = models.ForeignKey(to="Order",to_field="id",on_delete=models.CASCADE)
	# goodsid = models.ForeignKey(to="Goods",to_field="id",on_delete=models.CASCADE)
	num = models.IntegerField()
	price = models.IntegerField()